package test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Conference {
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int n = scanner.nextInt();
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        int[] arr = new int[n];
        for (int i = 0; i <n ; i++) {
            int begin = scanner.nextInt();
            int end = scanner.nextInt();
            arr[i] = end;
            if (hashMap.containsKey(end)){
                if (begin>hashMap.get(end)){
                    hashMap.put(begin,end);
                }
                continue;
            }
            hashMap.put(end,begin);
        }
        int sum =1;
        int m =0;
        Arrays.sort(arr);
        for (int i = 1; i < arr.length; i++) {
            if (hashMap.get(arr[i])>=arr[m]){
                sum++;
                m = i;
            }
        }
        System.out.println(sum);
    }
}
